//
//  BaseViewController.swift
//  JIMWeiBo
//
//  Created by 陈恒均 on 2018/2/9.
//  Copyright © 2018年 陈恒均. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    // MARK:- 懒加载属性
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    var isLogin : Bool = UserAccountViewModel.shareInstance.isLogin
      
    // MARK:- 系统回调函数
    
    override func loadView() {
        

        isLogin ? super.loadView() : setupVisitorView()
       
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupNavItems()
    }
}
// MARK:- 设置UI界面
extension BaseViewController
{
    private func setupVisitorView() {
        view = visitorView
        
        visitorView.registerBtn.addTarget(self, action:#selector(BaseViewController.registerBtnClick), for:.touchUpInside)
        visitorView.LoginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    func setupNavItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
    }
}

// MARK:- 时间监听
extension BaseViewController
{
    @objc private func registerBtnClick() {
        print("registerBtnClick")
    }
    
    @objc private func loginBtnClick() {
        let oauthVc = OAuthViewController()
        let oauthNav = UINavigationController(rootViewController: oauthVc)
        
        present(oauthNav, animated: true, completion: nil)
        
        
    }
}



